﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows;

namespace WpfBinding
{
    public class TestModelInfo : INotifyPropertyChanged
    {
        private int _age = 0;
        private string city = string.Empty;

        public int Age
        {
            get { return _age; }
            set
            {
                _age = value;
                OnPropertyChanged("Age");
            }
        }
        public string City
        {
            get { return city; }
            set
            {
                city = value;
                OnPropertyChanged("City");
            }
        }

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
                //PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
    }

    public class TestModels : System.Collections.ObjectModel.ObservableCollection<TestModelInfo>
    {
        public TestModels()
        {
            Add(new TestModelInfo() { Age = 20, City = "Hz" });
            Add(new TestModelInfo() { Age = 21, City = "Yz" });
            Add(new TestModelInfo() { Age = 55, City = "Hz" });
            Add(new TestModelInfo() { Age = 23, City = "Yz" });
            Add(new TestModelInfo() { Age = 45, City = "Yz" });
        }
    }
}
